package com.example.secondhandspringboot.domain.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class GoodsCounted {
    private Long categoryId;
    private int nums;
    //最新一次操作时间
    private LocalDateTime lastTime;

    public Long getTimeDifference(){
        // 获取当前时间的Instant
        Instant nowInstant = Instant.now();

        // 将给定的LocalDateTime转换为Instant（假设在系统默认时区）
        ZonedDateTime zonedDateTime = lastTime.atZone(ZoneId.systemDefault());
        Instant comparedInstant = zonedDateTime.toInstant();

        // 计算两个Instant之间的时间差
        Duration duration = Duration.between(comparedInstant, nowInstant);

        // 获取相差的秒数
        return duration.getSeconds(); // 使用Math.abs确保结果为正
    }
}
